#pragma once
#include <stdio.h>
#include <stdint.h>
#include <string.h>
typedef struct {
    char     chunkID[4];      // "RIFF"
    uint32_t chunkSize;       // 文件总大小-8
    char     format[4];       // "WAVE"
} RIFFHeader;

typedef struct {
    char     subchunkID[4];   // "fmt "
    uint32_t subchunkSize;    // fmt块大小（16 for PCM）
    uint16_t audioFormat;     // 1=PCM
    uint16_t numChannels;     // 声道数
    uint32_t sampleRate;      // 采样率（Hz）
    uint32_t byteRate;        // 每秒字节数
    uint16_t blockAlign;      // 每个样本的字节数
    uint16_t bitsPerSample;   // 位深度
} FmtHeader;

typedef struct {
    char     dataID[4];       // "data"
    uint32_t dataSize;        // 音频数据大小
} DataHeader;

// 能读到相同的原因是系统内存对齐规则会主动加上3字节对齐后面的uint32_t
// typedef struct {
//     char     dataID;      
//     uint32_t dataSize;        // 音频数据大小
// } DataHeader;




void printfWav(RIFFHeader* riff,FmtHeader* fmt,DataHeader* data){
     // 打印头信息
    printf("======== WAV Header Info ========\n");
    printf("File Size:      %u bytes\n", riff->chunkSize + 8);
    printf("subchunkSize:%d\n",fmt->subchunkSize);
    printf("Audio Format:   %s\n", fmt->audioFormat == 1 ? "PCM" : "Compressed");
    printf("Channels:       %u\n", fmt->numChannels);
    printf("Sample Rate:    %u Hz\n", fmt->sampleRate);
    printf("Bit Depth:      %u-bit\n", fmt->bitsPerSample);
    printf("Byte Rate:      %u bytes/sec\n", fmt->byteRate);
    printf("Block Align:    %u bytes/sample\n", fmt->blockAlign);
    printf("Audio Data:     %u bytes\n", data->dataSize);
    // 计算时长（秒）
    double duration = (double)data->dataSize / fmt->byteRate;
    printf("Duration:       %.2f seconds\n", duration);
    printf("===============================\n");
}